<?php

/**
 * @author aisyah
 * @copyright 2012
 */



session_start();

header("Content-type:image/png");

$captcha_image = imagecreatefrompng("../images/latar.png");

$captcha_font = imageloadfont("../images/anonymous.gdf");

$captcha_text = substr(md5(uniqid('')),-6,6);

$_SESSION['captcha_session'] = $captcha_text;

$captcha_color = imagecolorallocate($captcha_image,rand(0, 100), rand(100, 150), rand(150, 250));

imagestring($captcha_image,$captcha_font, 15,5,$captcha_text,$captcha_color);

imagepng($captcha_image);

imagedestroy($captcha_image);

/*

function generate_image($code, $location, $fonts_dir)
{
     $image  = imagecreate(150, 60);           
     imagecolorallocate($image, rand(0, 100), rand(100, 150), rand(150, 250));
     $fonts = scandir($fonts_dir);
     
     $max = count($fonts) - 2;
     
     $width = 10;
     for ($i = 0; $i <= strlen($code); $i++)
     {     
         $textcolor = imagecolorallocate($image, 255, 255, 255);
         $rand = rand(2, $max);
         $font = imageloadfont($fonts_dir."/".$fonts[$rand]);
         
         $fh = imagefontheight($font);
         $fw = imagefontwidth($font);

         imagechar($image, $font, $width, rand(10, 50 - $fh), $code[$i], $textcolor);     
          $width = $width + $fw;
        
     }
             
     imagejpeg($image, $location."/".md5($code).".jpg", 100);
     imagedestroy($image);       
    
     return $code;
     
}

*/